package tu.main;

import tu.cityInfor.CityInformation;
import tu.linjiebiao.biao.ALGraph;
import tu.shortestPath.ShortestPath_Dij;
import tu.traffic.plane.linklist.plane_list;
import tu.traffic.train.linklist.train_list;

import java.util.Scanner;

public class Test {
    public final static int INFINITY = Integer.MAX_VALUE;      //最大值
    public static void main(String[] args) throws Exception {
        Object[] temp ={"成都","重庆","武汉","贵阳","昆明","南昌","北京","长沙","上海","杭州","南京","郑州","西安","兰州"};
        int[] time ={10,20,10,10,10,10,10,10,10,20,30,20,10,20};
        Object[] trainId = {"D226","D2026","D2596","D321"};
        Object[] tStartTime = {"8:00","9:00","12:00","15:00"};
        Object[] tArrTime = {"9:00", "10:00","15:00","20:00"};
        Object[] planeId = {"A123","A124","A125","A126"};
        Object[] pStartTime = {"8:00","9:00","12:00","15:00"};
        Object[] pArrTime = {"9:00", "10:00","15:00","20:00"};
        train_list t = new train_list();
        plane_list p = new plane_list();
        ShortestPath_Dij dij = new ShortestPath_Dij();
        t.create1(trainId, tStartTime, tArrTime);
        p.create1(planeId, pStartTime, pArrTime);
        ALGraph alg = new ALGraph(temp);
        CityInformation city = new CityInformation();
        city.create1(temp, time);
        Scanner input = new Scanner(System.in);
        while(true){
            System.out.println("==========================================================================");
            System.out.println("                             1.交 通 平 面 图                              ");
            System.out.println();
            System.out.println("                             2.查 看 城 市 信 息                           ");
            System.out.println();
            System.out.println("                             3.列 车 时 刻 表                              ");
            System.out.println();
            System.out.println("                             4.飞 机 航 班 表                              ");
            System.out.println();
            System.out.println("                             5.出 行                                       ");
            System.out.println();
            System.out.println("                             6.退 出                                       ");
            System.out.println("===========================================================================");
            System.out.print("请选择需要查询的项目：");
            int choose = input.nextInt();
            if(choose == 1){
                int[][] tu = alg.jz;
                System.out.println("成都 重庆 武汉 贵阳 昆明 南昌 北京 长沙 上海 杭州 南京 郑州 西安 兰州");
                for (int i = 0; i < tu.length; i++) {
                    for (int j = 0; j < tu.length; j++) {
                        System.out.print(" " + tu[i][j] + "   ");
                    }
                    System.out.println();
                }
            }
            else if(choose == 2){
                System.out.println("=========================================");
                System.out.println("            1.增 加 城 市                ");
                System.out.println("            2.删 除 城 市                ");
                System.out.println("            3.输 出 城 市 信 息          ");
                System.out.println("=========================================");
                System.out.print("请输入需要执行操作的序号：");
                switch(input.nextInt()){
                    case 1:
                        System.out.print("请输入需要插入的城市名称以及等候时间：");
                        city.insert2(input.next(), input.nextInt());
                        break;
                    case 2:
                        System.out.println("请输入需要删除的城市序号：");
                        city.remove(input.nextInt());
                        break;
                    case 3:
                        System.out.println("城市及其车站等候时间为：");
                        city.display();
                        break;
                    default:
                        System.out.println("无此选项");
                        break;
                }
            }
            else if(choose == 3){
                System.out.println("=========================================");
                System.out.println("            1.增 加 列 车                ");
                System.out.println("            2.删 除 列 车                ");
                System.out.println("            3.输 出 列 车 信 息          ");
                System.out.println("=========================================");
                System.out.print("请输入需要执行操作的序号：");
                switch(input.nextInt()){
                    case 1:
                        System.out.println("请输入需要增加的列车的信息：");
                        t.insert(input.next(), input.next(), input.next());
                        break;
                    case 2:
                        System.out.println("请输入需要删除的列车序号：");
                        t.remove(input.nextInt());
                        break;
                    case 3:
                        System.out.println("列车信息：");
                        t.display();
                        break;
                    default:
                        System.out.println("序号输入错误");
                        break;
                }
            }
            else if(choose == 4){
                System.out.println("=========================================");
                System.out.println("            1.增 加 航 班                ");
                System.out.println("            2.删 除 航 班                ");
                System.out.println("            3.输 出 航 班 信 息           ");
                System.out.println("=========================================");
                System.out.print("请输入需要执行操作的序号：");
                switch(input.nextInt()){
                    case 1:
                        System.out.println("请输入需要增加的航班的信息：");
                        p.insert(input.next(), input.next(), input.next());
                        break;
                    case 2:
                        System.out.println("请输入需要删除的航班序号：");
                        p.remove(input.nextInt());
                        break;
                    case 3:
                        System.out.println("航班信息：");
                        p.display();
                        break;
                    default:
                        System.out.println("序号输入错误");
                        break;
                }
            }
            else if(choose == 5){
                System.out.println("=========================================");
                System.out.println("            1.最 快 车 次                ");
                System.out.println("            2.最 省 车 次                ");
                System.out.println("            3.中 转 最 少 车 次           ");
                System.out.println("=========================================");
                System.out.println("请输入始发站：");
                String start1 = input.next();
                int start = -1;
                for (int i = 0; i < temp.length; i++) {
                    if (temp[i].equals(start1)) {
                        start = i;
                    }
                }
                System.out.println("请输入终点站：");
                String arr1 = input.next();
                int arr = -1;
                for (int i = 0; i < temp.length; i++) {
                    if(temp[i].equals(arr1)){
                        arr = i;
                    }
                }
                System.out.println("请输入您的最优决策方案");
                switch(input.nextInt()){
                    case 1:
                        System.out.println("最快车次为：");
                        int[] shortPath = dij.Dijkstra(alg.jz_time,start,temp,arr,false);
                        break;
                    case 2:
                        System.out.println("最省车次为：");
                        int[] shortPath1 = dij.Dijkstra(alg.jz_money,start,temp,arr,false);
                        break;
                    case 3:
                        System.out.println("中转次数最少车次为：");
                        int[] shortPath2 = dij.Dijkstra(alg.jz_time,start,temp,arr,true);
                        break;
                    default:
                        System.out.println("输入序号无效");
                        break;       
                }
            }
            else if(choose == 6){
                break; 
            }
            else{
                System.out.println("请输入有效序号");
            }
        }
    }
}
